<?php
class Movie extends CI_Controller {
	
	function __construct() {
		// load controller parent
		parent::__construct ();
		// load 'MovieModel' model
		$this->load->model ( 'MovieModel' );
		// load helpers
		$this->load->helper ( 'url' );
		$this->load->helper ( 'form' );
	}
	
	// display all movies
	function index() {
		$data ['title'] = 'Movies List';
		$data ['movies'] = $this->MovieModel->fetchAllRows ( 'movies' );
		// load 'movie_view' view
		$this->load->view ( 'movie_view', $data );
	}
	
	// display all comments
	function comments() {
		$data ['title'] = 'Comment List';
		$data ['comments'] = $this->MovieModel->fetchRow ( $this->uri->segment ( 3 ), 'movie_id', 'movie_comments' );
		// load 'moviecomment_view' view
		$this->load->view ( 'moviecomment_view', $data );
	}
	
	// insert comment
	function insert_comment() {
		$this->MovieModel->insertRow ( 'movie_comments', $_POST );
		redirect ( 'movie/comments/' . $_POST ['movie_id'] );
	}

}
?>